import 'dart:ffi';

import 'package:flutter/material.dart';
import 'package:flutter_yd_simple/Project/ScanModule/DistributeScan/DistributeScanPage.dart';
import 'package:flutter_yd_simple/Project/ScanModule/SignScan/SignScanPage.dart';
import 'package:fluttertoast/fluttertoast.dart';

class HomeItemView extends StatefulWidget {
  const HomeItemView({super.key});

  @override
  State<HomeItemView> createState() => _HomeItemViewState();
}

class _HomeItemViewState extends State<HomeItemView> {

  var itemAry = [{"title":"分发扫描","icon":"lib/Project/Images/Home/home_item_dis.png"},
                {"title":"签收扫描","icon":"lib/Project/Images/Home/home_item_sign.png"},
                {"title":"揽件扫描","icon":"lib/Project/Images/Home/home_item_colloct.png"},
                {"title":"打电话","icon":"lib/Project/Images/Home/home_item_call.png"},
                {"title":"发短信","icon":"lib/Project/Images/Home/home_item_sms.png"},
                {"title":"打电话","icon":"lib/Project/Images/Home/home_item_call.png"},
                {"title":"更多","icon":"lib/Project/Images/Home/home_item_more.png"}];

  var itemAry2 = [{"title":"分发扫描2","icon":"lib/Project/Images/Home/home_item_dis.png"},
                {"title":"签收扫描2","icon":"lib/Project/Images/Home/home_item_sign.png"},
                {"title":"揽件扫描2","icon":"lib/Project/Images/Home/home_item_colloct.png"},
                {"title":"打电话2","icon":"lib/Project/Images/Home/home_item_call.png"},
                {"title":"发短信2","icon":"lib/Project/Images/Home/home_item_sms.png"},
                {"title":"打电话2","icon":"lib/Project/Images/Home/home_item_call.png"},
                {"title":"更多2","icon":"lib/Project/Images/Home/home_item_more.png"}];

  Widget _gridItemBuilder(BuildContext context,int index) {
    return GestureDetector(
      onTap: () {
        disposeItemClickAction(itemAry[index]["title"]!,context);
      },
      child: Column(
        children: [
          Image.asset(itemAry[index]["icon"]!,width: 40,height: 40),
          Text(itemAry[index]["title"]!,style: const TextStyle(color: Color(0xFF222222),fontSize: 12))
        ],
      ),
    );
  }
  Widget _gridItemBuilder2(BuildContext context,int index) {
    return GestureDetector(
      onTap: () {
        disposeItemClickAction(itemAry2[index]["title"]!,context);
      },
      child: Column(
        children: [
          Image.asset(itemAry2[index]["icon"]!,width: 40,height: 40),
          Text(itemAry2[index]["title"]!,style: const TextStyle(color: Color(0xFF222222),fontSize: 12))
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return PageView(
      children: [
        GridView.builder(
          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 5
          ), 
          itemBuilder: _gridItemBuilder,
          itemCount: itemAry.length,
          physics: NeverScrollableScrollPhysics(),
        ),

        GridView.builder(
          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 5
          ), 
          itemBuilder: _gridItemBuilder2,
          itemCount: itemAry2.length,
          physics: NeverScrollableScrollPhysics(),
        )
      ],
    );
  }

  void disposeItemClickAction(String title,BuildContext buildContex) {
    if (title == "待签收") {
      Navigator.of(buildContex).pushNamed('/SignBaseOrder',arguments:'123');
    } else if(title == "分发扫描") {
      Navigator.push(buildContex, MaterialPageRoute(builder: (buildContex){
        return DisScanPageDemo();
      }));
    } else if(title == "签收扫描") {
      Navigator.push(buildContex, MaterialPageRoute(builder: (buildContex){
        return SignScanPageDemo();
      },settings: RouteSettings(arguments: '我是首页界面来的')));
    } else {
      Fluttertoast.showToast(msg: "暂未配置路由",gravity:ToastGravity.CENTER);
    }
  }
}